/*
 * @Author: zhoulei0232
 * @Date: 2021-06-24 15:41:17
 * @LastEditTime: 2021-07-27 17:41:42
 * @LastEditors: zhoulei0232
 * @Description:
 */
import { Module } from "vuex";
import { RootStateTypes } from "../index";

export interface AppStateTypes {
  userInfo: object;
  sidebarList: object;
}

const appModule: Module<AppStateTypes, RootStateTypes> = {
  namespaced: true,
  state: {
    userInfo: {
      token: "",
      userName: "",
      role: "",
    },
    sidebarList: [
      {
        icon: "el-icon-s-home",
        index: "dashboard",
        title: "系统首页",
        roles: ["AllMenu"],
      },
      {
        icon: "el-icon-s-order",
        index: "table",
        title: "基础表格",
        roles: ["AllMenu"],
      },
      {
        icon: "el-icon-document-copy",
        index: "tabs",
        title: "tab选项卡",
        roles: ["AllMenu"],
      },
      {
        icon: "el-icon-document",
        index: "4",
        title: "表单相关",
        roles: ["AllMenu"],
        subs: [
          {
            index: "form",
            title: "基本表单",
            roles: ["AllMenu"],
          },
        ],
      },
      {
        icon: "el-icon-document",
        index: "6",
        title: "工具菜单",
        roles: ["AllMenu"],
        subs: [
          {
            index: "rules",
            title: "校验",
            roles: ["AllMenu"],
          },
        ],
      },
      {
        icon: "el-icon-warning",
        index: "5",
        title: "错误处理",
        roles: ["AllMenu"],
        subs: [
          {
            index: "permission",
            title: "权限测试",
            roles: ["admin"],
          },
          {
            index: "404",
            title: "404页面",
            roles: ["AllMenu"],
          },
        ],
      },
    ],
  },
  mutations: {
    UPDATE_USERINFO: (state: any, val: object): void => {
      state["userInfo"] = val;
    },

    UPDATE_SIDEBARLIST: (state: any, val: object): void => {
      state["sidebarList"] = val;
    },
  },
  actions: {
    UpdateUserInfo: (ctx: any, val: object): void => {
      ctx.commit("UPDATE_USERINFO", val);
    },
    UpdateSideBarList: (ctx: any, val: object): void => {
      ctx.commit("UPDATE_SIDEBARLIST", val);
    },
  },
};

export default appModule;
